babl: fix memory leaks on error paths
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 13 Oct 2017 16:32:52 +0000 (18:32 +0200)
committerØyvind Kolås <pippin@gimp.org>
Sat, 11 Nov 2017 13:07:53 +0000 (14:07 +0100)
The database-focused functions of babl-cache are prone to
memory leaks when errors occur.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
babl/babl-cache.c

index 13badc58ef19e51bc612189fcef326893e2614da..dcc76f4064899df0b6f5182e1bd08ff773d324ed 100644 (file)
@@ -170,10 +170,15 @@ void babl_store_db (void)
   char *tmpp = calloc(8000,1);
   FILE *dbfile;
 
+  if (!tmpp)
+    return;
   snprintf (tmpp, 8000, "%s~", fish_cache_path ());
   dbfile  = fopen (tmpp, "w");
   if (!dbfile)
+  {
+    free (tmpp);
     return;
+  }
   fprintf (dbfile, "%s\n", cache_header ());
 
   /* sort the list of fishes by usage, making next run more efficient -
@@ -273,6 +278,7 @@ void babl_init_db (void)
             {
               fprintf (stderr, "%s:%i: loading of cache failed\n",
                               __FUNCTION__, __LINE__);
+              free (contents);
               return;
             }
 
@@ -315,6 +321,7 @@ void babl_init_db (void)
             Babl *conv = (void*)babl_db_find(babl_conversion_db(), &token[1]);
             if (!conv)
             {
+              free (contents);
               return;
             }
             else